home *** CD-ROM | disk | FTP | other *** search
/ Windows 95 API Bible / Windows 95 API Bible 3 Disc Set.iso / Win32 API Bible Book 1 of 3.iso / chapte21 / ex4.c < prev    next >
C/C++ Source or Header  |  1995-06-04  |  5KB  |  92 lines

  1. #include <genstub.c>
  2.  
  3. LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
  4. {
  5.    switch (uMsg)
  6.    {
  7.          case WM_COMMAND:
  8.                switch ( LOWORD( wParam ) )
  9.                {
  10.                      case IDM_TEST:
  11.                      {
  12.                            char szBuffer[MAX_PATH+100];
  13.                            UINT nRow = 0;
  14.                            UINT nDrive = 0;
  15.                            DWORD dwLogicalDrives = GetLogicalDrives();
  16.                            HDC hDC = GetDC( hWnd );
  17.  
  18.                            for ( nDrive = 0; nDrive<32; nDrive++ )
  19.                            {
  20.                               if ( dwLogicalDrives & (1 << nDrive) )
  21.                               { // Is drive available?
  22.                                  UINT  uType;                 // type of drive.
  23.                                  DWORD dwBytesPerSector = 0;  // bytes per sector
  24.                                  DWORD dwSectorsPerCluster=0; // sectors per cluster
  25.                                  DWORD dwTotalClusters = 0;   // total clusters
  26.                                  DWORD dwFreeClusters = 0;    // free clusters
  27.                                  DWORD dwVolumeSerialNumber=0;// volume ser number
  28.                                  DWORD dwMaxNameLength=0;     // max component length
  29.                                  DWORD dwFileSystemFlags=0;   // file system flags
  30.                                  DWORD dwFreeSpace = 0;       // free space
  31.                                  DWORD dwTotalSpace = 0;      // total space
  32.                                  char szFileSysName[129];     // name of file system
  33.                                  char szLabel[129];           // name of volume
  34.  
  35.                                  // Get disk information.
  36.                                  wsprintf( szBuffer, "%c:\\", nDrive+'A' );
  37.                                  uType = GetDriveType( szBuffer );
  38.                                  GetDiskFreeSpace( szBuffer, &dwBytesPerSector,
  39.                                                    &dwSectorsPerCluster,
  40.                                                    &dwFreeClusters,
  41.                                                    &dwTotalClusters );
  42.                                  GetVolumeInformation( szBuffer, szLabel,
  43.                                                        sizeof( szLabel ) - 1,
  44.                                                        &dwVolumeSerialNumber,
  45.                                                        &dwMaxNameLength,
  46.                                                        &dwFileSystemFlags,
  47.                                                        szFileSysName,
  48.                                                        sizeof( szFileSysName ) - 1 );
  49.                                  dwFreeSpace = dwBytesPerSector *
  50.                                                dwSectorsPerCluster * dwFreeClusters;
  51.                                  dwTotalSpace = dwBytesPerSector *
  52.                                                 dwSectorsPerCluster * dwTotalClusters;
  53.  
  54.                                  // Print out information.
  55.                                  wsprintf( &szBuffer[3],
  56.                                            " Label: %s, System: %s, Long Names: %s ",
  57.                                            szLabel, szFileSysName,
  58.                                            (dwMaxNameLength == 255) ?
  59.                                            "TRUE" : "FALSE" );
  60.                                  TextOut( hDC, 0, 20 * nRow, szBuffer,
  61.                                           lstrlen( szBuffer ) );
  62.                                  wsprintf( szBuffer,
  63.                                           " Type: %s, Disk Space: %ld, Free: %ld",
  64.                                           ( uType == DRIVE_REMOVABLE ) ? "FLOPPY" :
  65.                                           (( uType == DRIVE_FIXED ) ?  "HARD DISK" :
  66.                                           (( uType == DRIVE_REMOTE ) ? "NETWORK" :
  67.                                           (( uType == DRIVE_CDROM ) ?  "CDROM" :
  68.                                           (( uType == DRIVE_RAMDISK ) ? "RAMDISK" :
  69.                                           (( uType == 1 ) ? "DOES NOT EXIST" :
  70.                                           "UNKNOWN DRIVE TYPE" ))))),
  71.                                           dwTotalSpace, dwFreeSpace );
  72.                                  TextOut( hDC, 0, 20 * (nRow+1),
  73.                                           szBuffer, lstrlen( szBuffer ) );
  74.                                  nRow += 2;
  75.                               }
  76.                            }
  77.                            ReleaseDC( hWnd, hDC );
  78.                      }
  79.                      break;
  80.                      case IDM_EXIT:
  81.                            DestroyWindow( hWnd );
  82.                            break;
  83.                }
  84.                break;
  85.          case WM_DESTROY:
  86.                PostQuitMessage( 0 );
  87.                break;
  88.          default:
  89.                return (DefWindowProc(hWnd, uMsg, wParam, lParam));
  90.    }
  91.    return (NULL);
  92. }